<?php

namespace iBrand\Shop\Backend\Console;

use iBrand\Component\Goods\Models\Season;
use iBrand\Shop\Backend\Model\City;
use Illuminate\Console\Command;

class ShopCityCommand extends Command
{

    protected $signature = 'shop-city:factory';

    protected $description = 'shop city factory.';

    /**
     * Execute the console command.
     */
    public function handle()
    {
        $data = $this->cityData();
        if (count($data) > 0) {
            foreach ($data as $item) {
                City::create($item);
            }
        }

        $seasons = Season::all();
        if ($seasons->count() == 0) {
            Season::create(['name' => '春季']);
            Season::create(['name' => '夏季']);
            Season::create(['name' => '秋季']);
            Season::create(['name' => '冬季']);
        }
    }

    private function cityData()
    {
        $data = config('city');

        foreach ($data as $key => $item) {
            if (City::where('name', $item['name'])->first()) {
                unset($data[$key]);
            }
        }

        return $data;
    }

}